package com.in.universityinfo;

import java.util.List;

import android.os.Bundle;
import android.widget.TextView;

import com.in.universityinfo.constant.ConstantVariables;
import com.in.universityinfo.database.UniversityDatasource;
import com.in.universityinfo.model.UniversitiesAdapterModel;

public class UniversityInformationActivity extends BaseActivity {

	private UniversityDatasource database;
	private List<UniversitiesAdapterModel> listUniversities;
	private TextView txtSelectedInfo;
	private TextView txtAddress;
	private TextView txtCity;
	private TextView txtState;
	private TextView txtPhone;
	private TextView txtEmail;
	private TextView txtWebsite;

	private String strSelectedState;
	private String strSelectedCity;
	private String strSelectedUniversity;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_university_information);

		// get screen parameters
		strSelectedState = getIntent().getStringExtra(
				ConstantVariables.EXTRA_STATE);
		strSelectedCity = getIntent().getStringExtra(
				ConstantVariables.EXTRA_CITY);

		strSelectedUniversity = getIntent().getStringExtra(
				ConstantVariables.EXTRA_UNIVERISTY);

		// Set text
		txtSelectedInfo = (TextView) findViewById(R.id.txtSelectedInfo);
		String selectedInfo = "The Information of \n" + strSelectedUniversity ;

		txtSelectedInfo.setText(selectedInfo);

		txtAddress = (TextView) findViewById(R.id.txtAddress);
		txtCity = (TextView) findViewById(R.id.txtCity);
		txtState = (TextView) findViewById(R.id.txtState);
		txtPhone = (TextView) findViewById(R.id.txtPhone);
		txtEmail = (TextView) findViewById(R.id.txtEmail);
		txtWebsite = (TextView) findViewById(R.id.txtWebsite);

		database = new UniversityDatasource(getApplicationContext());
		setupAdmob();
		share();
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		database.open();
		initData();
	}

	private void initData() {

		listUniversities = database.getUniversityInformation(strSelectedState,
				strSelectedCity, strSelectedUniversity);

		if (listUniversities.size() > 0) {
			UniversitiesAdapterModel model = listUniversities.get(0);
			txtAddress.setText(": " + model.getAddress().trim());
			txtCity.setText(": " + model.getCity().trim());
			txtState.setText(": " + model.getState().trim());
			txtPhone.setText(": " + model.getPhone().trim());
			txtEmail.setText(": " + model.getEmail().trim());
			txtWebsite.setText(": " + model.getWebsite().trim());

		}

	}

	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
		database.close();
	}
}
